/*
 * @Author: Jiagang Chen
 * @Date: 2021-11-24 16:29:03
 * @LastEditors: Jiagang Chen
 * @LastEditTime: 2021-11-26 03:04:43
 * @Description: ...
 * @Reference: ...
 */
#ifndef _VILENS_CAMERA_PROCESSOR_H_
#define _VILENS_CAMERA_PROCESSOR_H_

#include "lci_slam/vilens/camera/feature_tracker/CamBase.h"
#include "lci_slam/vilens/camera/feature_tracker/TrackKLT.h"
#include "lci_slam/vilens/common_header.h"
#include "lci_slam/vilens/utility/helper.h"

using namespace ov_core;

namespace vilens {

class cameraDatabase {
public:
    typedef std::shared_ptr<cameraDatabase> Ptr;
    cameraDatabase();
    ~cameraDatabase(){};

    std::mutex mtxProcess;  // TODO
};

class cameraProcessor {
public:
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
    typedef std::shared_ptr<cameraProcessor> Ptr;

    cameraProcessor();
    ~cameraProcessor();
    void setConfig();
    bool processMono(double timestamp, const cv::Mat &img, int cam_id,
                     const cv::Mat &mask = cv::Mat());
    bool processStereo(double timestamp, const cv::Mat &img0,
                       const cv::Mat &img1, int cam_id0, int cam_id1,
                       const cv::Mat &mask0 = cv::Mat(),
                       const cv::Mat &mask1 = cv::Mat());

    cameraDatabase::Ptr cameraDatabasePtr;

protected:
    bool judgeKeyframe();
    cv::Mat createMask(const size_t &cam_id);

    ov_core::TrackBase::Ptr featureTrackerPtr;
    std::unordered_map<size_t, CamBase::Ptr> trackCameras;
    ov_core::FeatureDatabase::Ptr featureDatabase;
    double lastImageProcessTime = -1;
    double lastlastImageProcessTime = -1;

    int maxNumPoints = 250;
    bool downsampleCameras = true;
    bool isStereo = true;
    ov_core::TrackBase::HistogramMethod methodHist =
        ov_core::TrackBase::HistogramMethod::CLAHE;
    int fastThreshold = 20;
    int minPixDist = 10;
    int gridX = 5;
    int gridY = 5;
};

}  // namespace vilens

#endif